﻿using M_Manufacture.API.Application.Command.ProductionPlanCommand;
using M_Manufacture.Repository.Interface;
using MediatR;

namespace M_Manufacture.API.Application.CommandHandlers.ProductionPlanCommandHandler
{
    /// <summary>
    /// 排程
    /// </summary>
    public class UpdateCommandHandeler : IRequestHandler<UpdateCommand, int>
    {
        /// <summary>
        /// 生产计划仓储接口
        /// </summary>
        protected readonly IProductionPlanRepository productionPlanRepository;

        public UpdateCommandHandeler(IProductionPlanRepository productionPlanRepository)
        {
            this.productionPlanRepository = productionPlanRepository;
        }
        public async Task<int> Handle(UpdateCommand request, CancellationToken cancellationToken)
        {
            var ss = await productionPlanRepository.GetModelsAsync(request.ProductionPlanId);
            ss.StartingDate=request.StartingDate;
            ss.EndingDate=request.EndingDate;
            ss.ProductionStatus = "已排程";
            return await productionPlanRepository.UpdateAsync(ss);
        }
    }
}
